package com.slimbloody.service;

import com.google.protobuf.InvalidProtocolBufferException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;

@Service
@Slf4j
public class PBService {
  /*
  public void recordCost(TcmQualityFeature.UserTcmQualityFeature userTcmQualityFeature, Integer size) throws InvalidProtocolBufferException {
    int serializedSize = userTcmQualityFeature.getSerializedSize();
    log.info("{} serializedSize: {} B, {} KB", size, serializedSize, serializedSize / 1024);
    StopWatch stopWatch = new StopWatch();
    stopWatch.start("serialize");
    byte[] byteArray = userTcmQualityFeature.toByteArray();
    stopWatch.stop();

    stopWatch.start("deserialize");
    TcmQualityFeature.UserTcmQualityFeature recover = TcmQualityFeature.UserTcmQualityFeature.parseFrom(byteArray);
    stopWatch.stop();
    for (StopWatch.TaskInfo taskInfo : stopWatch.getTaskInfo()) {
      log.info("{} {} cost: {}ns", size, taskInfo.getTaskName(), taskInfo.getTimeNanos());
    }
  }

  public TcmQualityFeature.UserTcmQualityFeature buildAvgList(int size) {
    TcmQualityFeature.UserPricePref.Builder uppBuilder = TcmQualityFeature.UserPricePref.newBuilder();
    uppBuilder.setLpref(1000);
    uppBuilder.setMpref(4000);
    uppBuilder.setHpref(5000);
    TcmQualityFeature.UserPricePref upp = uppBuilder.build();

    TcmQualityFeature.FeatureItem.Builder itemBuilder = TcmQualityFeature.FeatureItem.newBuilder();
    TcmQualityFeature.UserTcmQualityFeature.Builder builder = TcmQualityFeature.UserTcmQualityFeature.newBuilder();
    for (int i = 0; i < size; ++i) {
      itemBuilder.clear();
      itemBuilder.setOrigin("埃塞");
      itemBuilder.setCnName("999牌党参");
      itemBuilder.setUpf(upp);
      TcmQualityFeature.FeatureItem item = itemBuilder.build();
      builder.addItem(item);
    }

    TcmQualityFeature.UserTcmQualityFeature list = builder.build();
    builder.clear();
    return list;
  }

  public TcmQualityFeature.UserTcmQualityFeature buildMaxList(int size) {
    TcmQualityFeature.UserPricePref.Builder uppBuilder = TcmQualityFeature.UserPricePref.newBuilder();
    uppBuilder.setLpref(1000);
    uppBuilder.setMpref(4000);
    uppBuilder.setHpref(5000);
    TcmQualityFeature.UserPricePref upp = uppBuilder.build();

    TcmQualityFeature.FeatureItem.Builder itemBuilder = TcmQualityFeature.FeatureItem.newBuilder();
    TcmQualityFeature.UserTcmQualityFeature.Builder builder = TcmQualityFeature.UserTcmQualityFeature.newBuilder();
    for (int i = 0; i < size; ++i) {
      itemBuilder.clear();
      itemBuilder.setOrigin("埃塞俄比亚");
      itemBuilder.setUpf(upp);
      itemBuilder.setCnName("80000牌党参");
      TcmQualityFeature.FeatureItem item = itemBuilder.build();
      builder.addItem(item);
    }

    TcmQualityFeature.UserTcmQualityFeature list = builder.build();
    builder.clear();
    return list;
  }
   */
}
